package com.xique.door.service.impl.estate;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xique.common.core.utils.DateUtils;
import com.xique.common.core.utils.MathUtil;
import com.xique.common.core.utils.SecurityUtils;
import com.xique.common.core.utils.StringUtils;
import com.xique.door.bean.dao.estate.EstateUserListDAO;
import com.xique.door.bean.domain.WxMessageTemplate;
import com.xique.door.bean.domain.estate.EstateUser;
import com.xique.door.bean.request.estate.EstateUserListRequest;
import com.xique.door.mapper.estate.EstateUserMapper;
import com.xique.door.service.estate.IEstateUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author shd
 * @create 2022/6/9 11:42
 */
@Service
public class EstateUserServiceImpl extends ServiceImpl<EstateUserMapper, EstateUser> implements IEstateUserService {

    @Autowired
    private EstateUserMapper estateUserMapper;

    @Override
    public int insert(EstateUser user) {
        user.setCustomId(System.currentTimeMillis() + MathUtil.getRandom(15));
        user.setCreateUser(SecurityUtils.getUserId());
        user.setCreateTime(DateUtils.getNowDate());
        user.setUpdateUser(SecurityUtils.getUserId());
        user.setUpdateTime(DateUtils.getNowDate());
        return estateUserMapper.insert(user);
    }

    @Override
    public List<EstateUserListDAO> list(EstateUserListRequest request) {
        return estateUserMapper.list(request);
    }

    @Override
    public IPage<EstateUserListDAO> page(EstateUserListRequest request) {
        Page<EstateUserListDAO> page = new Page<>();
        if (StringUtils.isNotNull(request.getPageNum()) && StringUtils.isNotNull(request.getPageSize())) {
            page.setCurrent(request.getPageNum());
            page.setSize(request.getPageSize());
        }
        return estateUserMapper.page(page, request);
    }
}
